﻿namespace Utils.DialogManagement
{
	public class InputDialog : DialogBase, IInputDialog
	{
		public InputDialog(
			DialogLayeringHelper dialogLayeringHelper, 
			DialogMode dialogMode,
			string message,
			UiDispatcher dispatcher)
			: base(dialogLayeringHelper, dialogMode, dispatcher)
		{
			_dispatcher = dispatcher;
			_dispatcher.Invoke(() =>
				{
					_inputDialogControl = new InputDialogControl(message);
					SetContent(_inputDialogControl);
				});
		}

		private readonly UiDispatcher _dispatcher;

		private InputDialogControl _inputDialogControl;

		#region Implementation of IMessageDialog

		public string Message
		{
			get
			{
				var text = string.Empty;
				_dispatcher.Invoke((
					() => text = _inputDialogControl.Message));
				return text;
			}
			set
			{
				_dispatcher.Invoke((
					() => _inputDialogControl.Message = value));
			}
		}

		public string Value
		{
			get
			{
				var text = string.Empty;
				_dispatcher.Invoke((
					() => text = _inputDialogControl.Value));
				return text;
			}
		}

		#endregion
	}
}